package com.ant.storage.controller;


import com.ant.storage.common.ResultPage;
import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.DepreciationDto;
import com.ant.storage.pojo.Depreciation;
import com.ant.storage.pojo.DepreciationDetails;
import com.ant.storage.service.IDepreciationService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author melon
 * @since 2023-12-23
 */
@RestController
@RequestMapping("/depreciation")
public class DepreciationController {


    @Autowired
    private IDepreciationService depreciationService;


    @ApiOperation(value = "获取物品库存数据列表")
    @GetMapping("/getDepreciationList")
    public ResultPage getDepreciationList(DepreciationDto dto) {
        return ResultPage.success("操作成功", depreciationService.queryList(dto));
    }

    @ApiOperation(value = "保存信息")
    @PostMapping("/DepreciationSave")
    public ResultVo DepreciationSave(@RequestBody @Valid Depreciation dto , BindingResult result) {
        return depreciationService.DepreciationSave(dto,result);
    }

    @ApiOperation(value = "id查询详情")
    @GetMapping("/findDepreciationById/{id}")
    public ResultVo findDepreciationById(@PathVariable("id") Integer id) {
        return ResultVo.success("操作成功", depreciationService.findDepreciationById(id));
    }

    @ApiOperation(value = "车辆立列表")
    @GetMapping("/findCarInfoList")
    public ResultVo findCarInfoList() throws Exception {
//        List<DepreciationDetails> carInfoList = depreciationService.findCarInfoList();
//        depreciationService.saveDepreciation(carInfoList,1);
        List<DepreciationDetails> detailsList = depreciationService.findDepreciationList();
        depreciationService.saveDepreciation(detailsList,2);
        return ResultVo.success("操作成功");
    }

    @ApiOperation(value = "上传商品")
    @PostMapping("/uploadDepreciation")
    public ResultVo uploadDepreciation(@RequestParam("file") MultipartFile file){
        return depreciationService.uploadDepreciation(file);
    }
}
